package com.mantou.cdl.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 线程池多例工厂
 * 
 * @author wubp
 * 
 */
public class ThreadPoolFactory {

	/**
	 * 多例
	 * 
	 * @return 缓存的线程池
	 */
	public static ExecutorService getCachedThreadPool(String name) {
		return Executors.newCachedThreadPool(new DefaultThreadFactory(name));
	}

	/**
	 * 多例
	 * 
	 * @return 单线程池
	 */
	public static ExecutorService getSingleThreadExecutor(String name) {
		return Executors
				.newSingleThreadExecutor(new DefaultThreadFactory(name));
	}

	/**
	 * 多例
	 * 
	 * @param nThreads
	 *            线程数
	 * @return 返回指定线程数的池
	 */
	public static ExecutorService getFixedThreadPool(int nThreads,String name) {
		return Executors.newFixedThreadPool(nThreads,new DefaultThreadFactory(name));
	}

}
